/*
 * author      : dormi330
 * date        : 2018/7/17
 * description : TODO
 */

package com.deep.trade.infrastructure.mybatis.refund;

import com.deep.trade.application.AppRuntimeEvn;
import com.deep.trade.domain.refund.RefundOrder;
import com.deep.trade.domain.refund.RefundRepository;
import com.deep.trade.domain.refund.RefundType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class MybatisRefundRepository implements RefundRepository {

    @Autowired
    private AppRuntimeEvn appRuntimeEvn;

    @Autowired
    private RefundTypeMapper refundTypeMapper;

    @Autowired
    private RefundOrderMapper refundOrderMapper;

    @Override
    public void insertRefundType(RefundType refundType) {
        refundType.setTenantCode(appRuntimeEvn.getTenantCode());
        refundTypeMapper.insert(refundType);
    }

    @Override
    public void insertRefundApply(RefundOrder refundOrder) {
        refundOrder.setTenantCode(appRuntimeEvn.getTenantCode());
        refundOrderMapper.insert(refundOrder);
    }

    @Override
    public void updateRefundApplyStatus(RefundOrder refundOrder) {
        refundOrderMapper.updateStatus(
                appRuntimeEvn.getTenantCode(),
                refundOrder.getId(),
                refundOrder.getVersion(),

                refundOrder.getStatus(),
                refundOrder.getRejectReason(),
                refundOrder.getAuditAt(),
                refundOrder.getUpdatedBy());
    }
}
